package com.cincc.cinccimdemo.ui;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.cincc.cinccimdemo.R;
import com.cincc.im.core.IMSipPhoneCtrl;
import com.gyf.immersionbar.ImmersionBar;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;

public class LoginActivity extends IMBaseActivity {
    private static final String TAG = "LoginActivity";

    EditText accountEdit;
    EditText vccidEdit;
    EditText passwordEdit;
    EditText domainEdit;
    EditText portEdit;


//    @Override
//    protected void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_login);
//        initView();
//        ImmersionBar.with(this).statusBarDarkFont(true).init();
//    }

    @Override
    protected int contentLayout() {
        return R.layout.activity_login;
    }

    @Override
    protected void bindViews() {
        super.bindViews();
        toolbar.setVisibility(View.GONE);
        ImmersionBar.with(this).statusBarDarkFont(true).init();
        accountEdit = findViewById(R.id.edit_one);
        vccidEdit = findViewById(R.id.edit_two);
        passwordEdit = findViewById(R.id.edit_three);
        domainEdit = findViewById(R.id.edit_four);
        portEdit = findViewById(R.id.edit_five);

        accountEdit.setText("3001");
        vccidEdit.setText("100001");
        passwordEdit.setText("00000000");
        domainEdit.setText("192.168.2.191");
        portEdit.setText("5049");
    }

    public void onClick(View view) {
        BasePopupView loading = new XPopup.Builder(this).asLoading("正在登录").show();
        IMSipPhoneCtrl.getInstance().initialIm(this, accountEdit.getText().toString(), vccidEdit.getText().toString());
        IMSipPhoneCtrl.getInstance().login(this, passwordEdit.getText().toString(), domainEdit.getText().toString(), Integer.parseInt(portEdit.getText().toString()),"111111111", new IMSipPhoneCtrl.OneInitParamCallBack() {
            @Override
            public void onInitResult(int code) {
                Log.e(TAG, "onInitResult: " + code);
                if (code == 200) {
                    openMain();
                }
                runOnUiThread(loading::dismiss);
            }
        });
    }

    private void openMain() {
        Intent i = new Intent(this, MainActivity.class);
        startActivity(i);
        finish();
    }
}
